import { NextApiRequest, NextApiResponse } from "next";
import { searchDatas } from "@/lib/userdata_database_method";

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
    // 设置 CORS 头部
    res.setHeader('Access-Control-Allow-Origin', '*'); // 允许所有来源
    const { username, email } = req.body;


    const sqlUsername = 'SELECT * FROM users_data WHERE username = ?';
    const paramsUsername = [username];

    try {
        const dbresultUsername = await searchDatas(sqlUsername, paramsUsername);

        if (dbresultUsername.length) {
            res.status(200).json({ canLogup: false, type: "用户名已被注册" });
            return;
        }


        res.status(200).json({ canLogup: true });
        return;

    }
    catch (error) {
        console.log(error);
    }
}